class Accounts < ActiveRecord::Base
  set_primary_key "id"

  def calculateBrokerage(amount)
    result = (brokerage_percents*amount)/100
    if (not_less_then != nil and not_less_then > result)
      result = not_less_then
    end
    result
  end

  def calculateNetAmount(gross)
    net = ((100 - brokerage_percents) * gross)/100
    if (not_less_then != nil and gross - net < not_less_then)
      net = gross - not_less_then
    end
    net
  end

  def calculateZeroPrice(gross, quantity)
    net = gross * (100 / (100 - brokerage_percents))
    if (not_less_then != nil and net - gross < not_less_then)
      net = gross + not_less_then
    end
    net/quantity
  end
  
end
